package com.jk.smartelderlycare.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hhk
 * @version 1.0
 * @ClassName TopicRabbitConfig
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/30 15:55
 */
@Configuration
public class TopicRabbitConfig {
    //最终  静态  表示常量
    final static String message = "topic.message";
    final static String messages = "topic.messages";


    //创建队列
    @Bean
    public Queue queueMessage(){
        return new Queue(TopicRabbitConfig.message);
    }
    @Bean
    public Queue queueMessages(){
        return new Queue(TopicRabbitConfig.messages);
    }
    @Bean
    //创建topic交换器(TopicExchange):topic 是RabbitMQ中最灵活的一种方式，可以根据routing_key自由的绑定不同的队列
    public TopicExchange exchange(){
        return new TopicExchange("exchange");
    }

    //交换机与队列绑定
                                            //传参：队列            交换机
    @Bean
    public Binding bindingExchangeMessage(Queue queueMessage ,TopicExchange exchange){
            //          queueMessage队列    绑定到exchange     用topic.message 名字来绑定
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
    }
    @Bean
    public Binding bindingExchangeMessages(Queue queueMessages ,TopicExchange exchange){
        //          queueMessage队列    绑定到exchange      名字以topic.开头的都绑定
        return BindingBuilder.bind(queueMessages).to(exchange).with("topic.#");
    }





}
